package com.code.splider.controller;

import java.util.List;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.DomNodeList;
import com.gargoylesoftware.htmlunit.html.HtmlDivision;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableCell;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow;

public class TestEX4 {
	
	private static WebClient webClient;

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static void main(String[] args) {
		try {

			webClient = new WebClient(BrowserVersion.FIREFOX_45);
			webClient.getOptions().setJavaScriptEnabled(true);
			
			webClient.setAjaxController(new NicelyResynchronizingAjaxController());
			webClient.getOptions().setThrowExceptionOnScriptError(false);
			webClient.getOptions().setCssEnabled(false); 
			webClient.getOptions().setActiveXNative(false);  
			HtmlPage page = webClient.getPage("http://www.dszuqiu.com/panlu/242331");
			page.getHtmlElementById("tabtypeid2").click();
			page.getHtmlElementById("tabid2").click();
			page.getHtmlElementById("td10").click();
			Thread.sleep(3000);
			HtmlDivision div = (HtmlDivision)page.getElementById("history_table");
			DomNodeList<HtmlTable> nodes =	(DomNodeList)div.getChildNodes();
			for (HtmlTable htmlTable : nodes) {
				List<HtmlTableRow> list = 	htmlTable.getBodies().get(0).getRows();
				for (HtmlTableRow htmlTableRow : list) {
					List<HtmlTableCell> cells =	htmlTableRow.getCells();
					for (HtmlTableCell htmlTableCell : cells) {
						System.out.println(htmlTableCell.asText());
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
